#!/bin/sh
# author jjm2473

TIME_FILE=/etc/.timeset_last_power

trigger() {
	case "$1" in
	reboot)
		reboot
		;;
	poweroff)
		poweroff
		;;
	network)
		/etc/init.d/network restart
		;;
	esac
}

fuse() {
    local idle_t=$((`date '+%s'` - `date -r "$TIME_FILE" '+%s' 2>/dev/null || echo '0'`))
    if [ $idle_t -le 300 ]; then
        logger -p warn -t "timeset" "action too frequency, last action triggered at `date -r "$TIME_FILE"`"
        return
    fi
    touch /etc/.timeset_last_power && trigger $@
}

fuse "$1"
